package com.heima.wemedia.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heima.model.wemedia.pojos.WmNewsMaterial;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface WmNewsMaterialMapper extends BaseMapper<WmNewsMaterial> {

    /**
     * 保存文章和素材的关联关系
     *  TODO mapper.xml实现
     * @param wmMaterialIds 素材集合
     * @param newsId        文章ID
     * @param type          文章封面类型  0 无图 1 单图 3 多图 -1 自动
     */
    @Insert("<script> insert into wm_news_material (material_id, news_id, type, ord) values  " +
            "  <foreach collection='wmMaterialIds' item='materialId' index='ord' separator=',' > " +
            "  (#{materialId},#{newsId}, #{type}, #{ord})\n" +
            "  </foreach> </script>")
    public void saveRelations(@Param("wmMaterialIds") List<Integer> wmMaterialIds,
                              @Param("newsId") Integer newsId,
                              @Param("type") Short type);
}
